class DemoException(Exception):
    """为这次演示定义的异常类型"""

def demo_exc_handing():
    print('-> coroutine started')
    while True:
        try:
            x = yield
        except DemoException:
            print ('*** DemoException handled. Continuing')
        else:
            print('*** coroutine received： {!r}'.format(x))
    # raise RuntimeError('This line should never run.')
    finally:
        print('-> coroutine ending')

exc_coro = demo_exc_handing()
next(exc_coro)

print(exc_coro.send(11))

print(exc_coro.send(22))

print(exc_coro.close())

print(exc_coro.throw(DemoException))
